<template>
	<view class="box">
		<view class="top" :style="{height:marginNavTop,top:0}">
			<view class="navbar" :style="{paddingTop:statusBarHeight,height:statusNavHeight}">
				<view class="navTop" :style="{height:statusNavHeight}">
					<view class="left" @click="goBack">
					</view>
					<view class="center">
						广场
					</view>
					<view class="right">

					</view>
				</view>
			</view>
		</view>
		<view class="bottom" :style="{paddingTop:marginNavTop}">
			<view class="waterfall">
				<view class="left-column">
					<view class="item" v-for="(item, index) in leftList" :key="index" @click="to(item)">
						<image :src="item.imageUrl" mode="widthFix"></image>
						<view class="content">
							<view class="title">{{item.title}}</view>
							<view class="user-info">
								<image class="avatar" :src="item.avatar"></image>
								<text class="username">{{item.username}}</text>
								<view class="likes">
									<text class="like-count">已售{{item.likes}}</text>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="right-column">
					<view class="item" v-for="(item, index) in rightList" @click="to(item)" :key="index">
						<image :src="item.imageUrl" mode="widthFix"></image>
						<view class="content">
							<view class="title">{{item.title}}</view>
							<view class="user-info">
								<image class="avatar" :src="item.avatar"></image>
								<text class="username">{{item.username}}</text>
								<view class="likes">
									<text class="like-count">已售{{item.likes}}</text>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				statusBarHeight: 0,
				statusNavHeight: 0,
				marginNavTop: 0,
				leftList: [],
				rightList: [],
				allList: [
					// 测试数据
					{
						imageUrl: '/static/img/test2.jpg',
						title: '前端开发，',
						avatar: '/static/img/test2.jpg',
						username: '小鸭呱呱呱',
						likes: 20
					},
					{
						imageUrl: '/static/img/test1.jpg',
						title: '求一份邻峰的工作',
						avatar: '/static/img/test1.jpg',
						username: 'Cc.',
						likes: 12
					},
					{
						imageUrl: '/static/img/test1.jpg',
						title: '求一份邻峰的工作',
						avatar: '/static/img/test1.jpg',
						username: 'Cc.',
						likes: 12
					},
					{
						imageUrl: '/static/img/test1.jpg',
						title: '求一份邻峰的工作',
						avatar: '/static/img/test1.jpg',
						username: 'Cc.',
						likes: 12
					},
					{
						imageUrl: '/static/img/test2.jpg',
						title: '求一份邻峰的工作',
						avatar: '/static/img/test1.jpg',
						username: 'Cc.',
						likes: 12
					},
					{
						imageUrl: '/static/img/test1.jpg',
						title: '求一份邻峰的工作',
						avatar: '/static/img/test1.jpg',
						username: 'Cc.',
						likes: 12
					},
					{
						imageUrl: '/static/img/test2.jpg',
						title: '求一份邻峰的工作',
						avatar: '/static/img/test1.jpg',
						username: 'Cc.',
						likes: 12
					},
					{
						imageUrl: '/static/img/test2.jpg',
						title: '求一份邻峰的工作',
						avatar: '/static/img/test1.jpg',
						username: 'Cc.',
						likes: 12
					},
				]
			}
		},
		created() {
			this.statusBarHeight = getApp().globalData.statusBarHeight + 'px'
			this.statusNavHeight = getApp().globalData.statusNavHeight + 'px'
			this.marginNavTop = (getApp().globalData.statusBarHeight + getApp().globalData.statusNavHeight + 6) + 'px'
			this.initWaterfall()
		},
		onReachBottom() {
			console.log('到底还在出发');
		},
		onLoad(option) {
			console.log(option, '传递的参数');
		},
		methods: {
			goBack() {
				uni.navigateBack()
			},
			// 初始化瀑布流
			initWaterfall() {
				this.allList.forEach((item, index) => {
					if (index % 2 === 0) {
						this.leftList.push(item)
					} else {
						this.rightList.push(item)
					}
				})
			},

			to() {
				uni.navigateTo({
					url: '/pages/squareDetails/squareDetails'
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.box {
		width: 100%;
		height: 100%;
		box-sizing: border-box;
		display: flex;
		flex-direction: column;

		.top {
			width: 100%;
			display: flex;
			flex-direction: column;
			box-sizing: border-box;
			position: fixed;
			z-index: 5;
			background-color: #fff;

			.navbar {
				width: 100%;
				// border: 2rpx solid red;
				box-sizing: border-box;
			}

			.navTop {
				width: 100%;
				display: flex;

				.left {
					width: 180rpx;
					height: 100%;
					box-sizing: border-box;
					padding-left: 40rpx;

					.image {
						width: 64rpx;
						height: 64rpx;
					}
				}

				.center {
					display: flex;
					align-items: center;
					justify-content: center;
					flex: 1;
					font-family: 思源黑体;
					font-size: 38rpx;
					font-weight: 500;
					letter-spacing: 0rpx;
					color: #000000;
				}

				.right {
					width: 180rpx;
					height: 100%;
				}
			}

		}

		.bottom {
			flex: 1;
			width: 100%;
			box-sizing: border-box;
			display: flex;
			flex-direction: column;
			background-color: #F7F8FA;
			padding: 0 12rpx;
			padding-bottom: 30rpx !important;

			.waterfall {
				display: flex;
				justify-content: space-between;
				padding: 10rpx;

				.left-column,
				.right-column {
					width: 48%;
				}

				.item {
					background-color: #FFFFFF;
					border-radius: 12rpx;
					margin-bottom: 20rpx;
					overflow: hidden;

					image {
						width: 100%;
						height: auto;
					}

					.content {
						padding: 16rpx;

						.title {
							font-size: 28rpx;
							color: #333;
							line-height: 1.4;
							margin-bottom: 12rpx;
						}

						.user-info {
							display: flex;
							align-items: center;

							.avatar {
								width: 40rpx;
								height: 40rpx;
								border-radius: 50%;
								margin-right: 10rpx;
							}

							.username {
								font-size: 24rpx;
								color: #666;
								flex: 1;
							}

							.likes {
								font-size: 24rpx;
								color: #999;
							}
						}
					}
				}
			}
		}
	}
</style>